package com.cug.smartranch.animal.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cug.smartranch.animal.admin.dao.entity.AnimalHealth;
import com.cug.smartranch.animal.admin.dto.req.AnimalHealthSaveReqDTO;
import com.cug.smartranch.animal.admin.dto.resp.AnimalHealthQueryRespDTO;
import com.cug.smartranch.animal.admin.service.AnimalHealthService;
import com.cug.smartranch.animal.admin.service.AnimalService;
import com.cug.smartranch.framework.result.Result;
import com.cug.smartranch.framework.web.Results;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 动物健康信息控制层
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "动物健康信息管理")
@RequestMapping("/api/animal-admin/animal/health")
public class AnimalHealthController {

    private final AnimalHealthService animalHealthService;
    private final AnimalService animalService;

    @Operation(summary = "用户创建当前时刻动物健康记录")
    @PostMapping("/create")
    public Result<Void> createAnimalHealth(@RequestBody AnimalHealthSaveReqDTO requestParam) {
        animalHealthService.createAnimalHealth(requestParam);
        return Results.success();
    }

    @Operation(summary = "(后端测试使用)用户创建当前时间之前的100条动物健康记录，用于测试以及造数据,如果该动物已经有超过100条当前时间之前的健康记录，则不用创建")
    @PostMapping("/createMock")
    public Result<Void> createMockAnimalHealth(@RequestParam("animalId") Long animalId) {
        animalHealthService.createMockAnimalHealth(animalId);
        return Results.success();
    }

    @Operation(summary = "查询某个动物近期100条健康状态记录")
    @GetMapping("/find")
    public Result<List<AnimalHealthQueryRespDTO>> findAnimalHealth(@RequestParam("animalId") Long animalId) {
        List<AnimalHealthQueryRespDTO> respDTO = animalHealthService.findAnimalHealth(animalId);
        return Results.success(respDTO);
    }

    @Operation(summary = "查看牲畜健康情况（饼状图）")
    @GetMapping("/allAnimalHealthRatio")
    public Result<Map<String,Double>> findAnimalHealthRatio() {
        Map<String,Double> map = animalHealthService.findAnimalHealthRatio();
        return Results.success(map);
    }
}
